package com.thinkingstar.iads.projectcenter.serviceImpl;

import com.thinkingstar.iads.datacenter.entity.*;
import com.thinkingstar.iads.datacenter.entity.common.dao.CommonDao;
import com.thinkingstar.iads.datacenter.entity.dao.*;
import com.thinkingstar.iads.projectcenter.entity.PcProjectConstantData;
import com.thinkingstar.iads.projectcenter.entity.PcProjectInfo;
import com.thinkingstar.iads.projectcenter.entity.PcSjpsFile;
import com.thinkingstar.iads.projectcenter.entity.PcTczlFile;
import com.thinkingstar.iads.projectcenter.entity.dao.*;
import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.QueryResult;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: ProjectTczlServiceImpl
 * @Description: 提出资料维护
 * @author z
 * @date  
 */
@IocBean
public class ProjectTczlServiceImpl {

	@Inject
	private DaoPcProjectData daoPcProjectData;

	@Inject
	private DaoTemplateVersion daoTemplateVersion;

	@Inject
	private DaoPcProjectConstantData daoPcProjectConstantData;

	@Inject
	private DaoDcProjectMention daoDcProjectMention;

	@Inject
	private DaoDcProjectDesignCell daoDcProjectDesignCell;

	@Inject
	private DaoDcCompoundTemplate daoDcCompoundTemplate;

	@Inject
	private DaoPcTczlFile daoPcTczlFile;

	@Inject
	private DaoDcProjectPutFord daoDcProjectPutFord;

	@Inject CommonDao commonDao;

	@Inject
	private DaoDcTemplateVariable daoDcTemplateVariable;

	public List<NutMap> getDcTczlFileList(NutMap param) {
		PcProjectInfo project_info = daoPcProjectData.fetch((String)param.get("project_id"));
		String phase_id = project_info.getProject_design_phase_id();
		String content_id = project_info.getProject_design_content_id();
		return daoDcProjectPutFord.getTczlFileList(content_id,phase_id);
	}




	public DcProjectPutFord getDcProjectPutFordById(String id) {
		return daoDcProjectPutFord.fetch(id);
	}

	public List<DcCompoundTemplate> getTemplateListByIds(String template_ids){
		String[] ids = template_ids.split(",");
		List<DcCompoundTemplate> list = new ArrayList<>();
		for (int i=0;i<ids.length;i++) {
			if (StringUtils.isNotEmpty(ids[i])) {
				list.add( daoDcCompoundTemplate.fetch(ids[i]));
			}
		}
		return list;
	}

	public String getTemplateByIds(String template_ids) {
		String[] ids = template_ids.split(",");
		String template_data = "";
		for (int i=0;i<ids.length;i++) {
			if (StringUtils.isNotEmpty(ids[i])) {
				DcCompoundTemplate template = daoDcCompoundTemplate.fetch(ids[i]);
				template_data+=template.getTemplate_name()+"、";
			}
		}
		return template_data;
	}


	public PcTczlFile getPcTczlFile(String project_id, String fileNum){
		PcTczlFile tczlFile = daoPcTczlFile.findByProjectAndFileNum(project_id,fileNum);
		return tczlFile;
	}

	public void insertOrUpdatePcTczlFile(String project_id,String sorting,String fileNum) {
		PcTczlFile tczlFile = daoPcTczlFile.findByProjectAndFileNum(project_id,fileNum);
		if (null!=tczlFile){
			tczlFile.setSorting(sorting);
			daoPcTczlFile.update(tczlFile);
		} else {
			tczlFile = new PcTczlFile();
			tczlFile.setSorting(sorting);
			tczlFile.setProject_id(project_id);
			tczlFile.setFileNum(fileNum);
			PcProjectInfo project_info = daoPcProjectData.fetch(project_id);
			tczlFile.setProjectName(project_info.getProject_name());
			daoPcTczlFile.insert(tczlFile);
		}
	}

	public List<DcTemplateVariable> getTemplateVariable(String template_id) {
		return daoDcTemplateVariable.getTemplateVariable(template_id);
	}

	public Map<String,String> getVariableValues(List<DcTemplateVariable> list, String project_id) {
		return daoDcTemplateVariable.getVariableValues(list,project_id);
	}
}
